﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeBudget
{
    public  class MoneySystem
    {
        private List<Expense> allExpenses = new List<Expense>();
        private List<Earning> allEarnings = new List<Earning>();

        public  decimal CalculateMoneyNow()
        {
            return CalculateEarnings() - 
                CalculateExpenses();
        }
        public decimal CalculateEarnings()
        {
            decimal totalEarnings = 0;
            foreach (var earning in allEarnings)
            {
                totalEarnings += earning.Amount;
            }
            return totalEarnings;
        }
        public decimal CalculateExpenses()
        {
            decimal totalExpenses = 0;
            foreach (var expense in allExpenses)
            {
                totalExpenses += expense.Amount;
            }
            return totalExpenses;
        }
        public void AddEarning(Earning earning)
        {
            allEarnings.Add(earning);
        }
        public void AddExpense(Expense expense)
        {
            allExpenses.Add(expense);
        }
        public List<Earning> GetEarnings()
        {
            return this.allEarnings;
        }
        public List<Expense> GetExpenses()
        {
            return this.allExpenses;
        }
        public List<Money> GetExpensesAsMoney()
        {
            List<Money> moneyList = new List<Money>();
            foreach (var item in allExpenses)
            {
                moneyList.Add(item);
            }
            return moneyList;
        }
        public List<Money> GetEarningsAsMoney()
        {
            List<Money> moneyList = new List<Money>();
            foreach (var item in allEarnings)
            {
                moneyList.Add(item);
            }
            return moneyList;
        }
    }
}
